package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-09-14
 * Time: 20:42
 */
class Result{
    public int sum = 0;
    public Object lock = new Object();
}
public class ThreadD29_1 {
    public static void main(String[] args) throws InterruptedException {
        Result result = new Result();
        Thread t = new Thread(){
            @Override
            public void run() {
                int sum = 0;
                for (int i = 0; i < 1000; i++) {
                    sum += i;
                }
                synchronized (result.lock){
                    result.sum = sum;
                    result.lock.notify();
                }
            }
        };
        t.start();
        synchronized (result.lock) {
            while(result.sum == 0){
                result.lock.wait();
            }
            System.out.println(result.sum);
        }
    }
}
